package com.asset.controller;

import com.asset.common.ErrorCode;
import com.asset.common.BaseResponse;
import com.asset.common.ResultUtils;
import com.asset.exception.ThrowUtils;
import com.asset.model.dto.asset.AssetQueryRequest;
import com.asset.model.vo.AssetDetailsVO;
import com.asset.model.vo.AssetVO;
import com.asset.service.AssetService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/asset")
public class AssetController {
    
    @Resource
    private AssetService assetService;

    @PostMapping("/list")
    public BaseResponse<PageInfo<AssetVO>> getAssetListPage(@RequestBody AssetQueryRequest assetQueryRequest) {
        ThrowUtils.throwIf(assetQueryRequest == null, ErrorCode.PARAMS_ERROR);
        PageInfo<AssetVO> assetListVOPage = assetService.getAssetListVOPage(assetQueryRequest);
        return ResultUtils.success(assetListVOPage);
    }
    
    @PostMapping("/getAssetDetailsById")
    public BaseResponse<AssetDetailsVO> getAsstDetails(Integer id) {
        ThrowUtils.throwIf(id == null, ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(assetService.getAssetById(id));
    }
}
